﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PatternBuilder
{
    class Program
    {
        static void Main(string[] args)
        {

            //可分步骤创建类
            House house =  new House.Builder().SetDoor(new Door()).SetWall(new Wall()).SetWin(new Window()).Build();  
        }
    }



    /// <summary>
    /// 使用嵌套类
    /// </summary>
    class House
    {
        Window window;
        Door door;
        Wall wall;

        public House(Builder builder)
        {
            this.window = builder.window;
            this.door = builder.door;
            this.wall = builder.wall; 
        }


        /// <summary>
        /// 构造类  拥有和house一样的属性
        /// </summary>
        public class Builder
        { 
            public Window window;
            public Door door;
            public Wall wall;

            public Builder SetWin(Window window)
            {
                this.window = window;
                return this;

            }
            public Builder SetDoor(Door door)
            {
               
                this.door = door;
                return this;

            }
            public Builder SetWall(Wall wall)
            { 
                this.wall = wall;
                return this;
            }


            /// <summary>
            /// 完全构造完毕 统一将builder成品交付house
            /// </summary>
            /// <returns></returns>
            public House Build()
            { 
                return new House(this); 
            }

        }

    }


    class Window
    { }

    class Door
    { }

    class Wall
    { }



}
